package com.novunda.platform.common.utils;

import com.novunda.platform.common.exception.NovException;
import com.novunda.platform.entities.Log;
import com.novunda.platform.entities.ReportLog;
import com.novunda.platform.enums.ValidateExceptionEnum;

/**
 * ..
 * 校验工具
 *
 * @author yangg
 * @since 2016/9/20.
 */
public class ValidateUtil {
    /**
     * 验证上报的审计记录
     *
     * @param log 审计对象
     * @return 校验结果
     */
    public static boolean validateReportLog(ReportLog log) {
        if (log == null) {
            throw new NovException(ValidateExceptionEnum.INVALID_LOG_NULL);
        }
        if (StringUtil.isEmpty(log.getName())) {
            throw new NovException(ValidateExceptionEnum.INVALID_LOG_NAME_NULL);
        }
        if (StringUtil.isEmpty(log.getType())) {
            throw new NovException(ValidateExceptionEnum.INVALID_LOG_TYPE_NULL);
        }
        if (log.getUserId() == null) {
            throw new NovException(ValidateExceptionEnum.INVALID_LOG_USER_NULL);
        }
        if (StringUtil.isEmpty(log.getDescription())) {
            throw new NovException(ValidateExceptionEnum.INVALID_LOG_DESC_NULL);
        }
        return true;
    }

    /**
     * 验证保存的审计记录
     *
     * @param log 审计对象
     * @return 校验结果
     */
    public static boolean validateLog(Log log) {
        if (log == null) {
            throw new NovException(ValidateExceptionEnum.INVALID_LOG_NULL);
        }
        if (StringUtil.isEmpty(log.getName())) {
            throw new NovException(ValidateExceptionEnum.INVALID_LOG_NAME_NULL);
        }
        if (StringUtil.isEmpty(log.getType())) {
            throw new NovException(ValidateExceptionEnum.INVALID_LOG_TYPE_NULL);
        }
        if (log.getUserName() == null) {
            throw new NovException(ValidateExceptionEnum.INVALID_LOG_USER_NULL);
        }
        if (StringUtil.isEmpty(log.getDescription())) {
            throw new NovException(ValidateExceptionEnum.INVALID_LOG_DESC_NULL);
        }
        return true;
    }
}
